package http.secure.common.keys.validator;

import http.secure.common.keys.validator.impl.MappedRepeatValidator;
import http.secure.common.keys.validator.impl.RedisRepeatValidator;

/**
 * Repeated request validator
 *
 * @date 2021.8.2
 * @see MappedRepeatValidator
 * @see RedisRepeatValidator
 */
public interface RepeatValidator {
    /**
     * Verify this request is expired
     *
     * @param timestamp     request timestamp (unit: millisecond)
     * @param effectiveTime effectiveTime (unit: second)
     * @return link expired return true
     */
    default boolean isExpired(long timestamp, long effectiveTime) {
        return System.currentTimeMillis() - timestamp > effectiveTime * 1000;
    }

    /**
     * Verify this request is repeated
     *
     * @param timestamp request timestamp
     * @param sign      request link signature
     * @return link repeated return true
     */
    boolean isRepeated(long timestamp, String sign);
}
